# Copyright (c) 2007 Kimmo Parviainen <kimvais@gmail.com>
# See the LICENSE file for details

def north(x,y):
	return x,y-2
def northeast(x,y):
	return (x+y%2),y-1
def southeast(x,y):
	return (x+y%2),y+1
def south(x,y):
	return (x,y+2)
def southwest(x,y):
	return (x-((y+1)%2),y+1)
def northwest(x,y):
	return (x-((y+1)%2),y-1)

directions = [north,northeast,southeast,south,southwest,northwest]
"""

def neighbours(x,y):
	ret = []
	for func in directions:
		ret+=(func(x,y),)
	return ret
"""
class position:
	def __init__(self,(coords),facing):
		self.x = coords[0]
		self.y = coords[1]
		self.f = facing
	def turn(self,direction,amount=1):
		if type(direction) == str:
			if direction[0].lower() == "l":
				direction = -1
			elif direction[0].lower() == "r":
				direction = 1
			else:
				raise ValueError("direction must be either -1,1,'left','right','l' or 'l'")
		self.f = (self.f+amount*direction)%6

	def walk(self,distance=1,backwards=False):
		direction = self.f
		if backwards:
			direction = (direction + 3) % 6
		self.move(direction,distance)

	def move(self,direction,distance):
		for i in range(distance):
			# print "At (%d,%d)" % (self.x,self.y)
			self.x,self.y = directions[direction](self.x,self.y)
			# print "Moved to (%d,%d)" % (self.x,self.y)
	
	def where(self):
		return (self.x,self.y,)
"""
	def get_neighbours(self):
		return neighbours(self.x,self.y)
		"""
